import "../globals.css";

import { Toaster } from "@/components/ui/toaster"
import { Toaster as SonnerToaster } from "@/components/ui/sonner"
import { Inter as FontSans } from "next/font/google"
import { cn } from "@/lib/utils"

import LayoutClient from "./LayoutClient"
import {getCurrentUser} from "@/lib/userService"
import dynamic from 'next/dynamic';

import { getDictionary } from "@/dictionaries/dictionaries"

import { wxJsConfig } from "@/pay/wxjssdk"

const TrackerProvider = dynamic(() => import('@/trackContext'), { ssr: false });
const fontSans = FontSans({
  subsets: ["latin"],
  variable: "--font-sans",
})

export default async function RootLayout({ children,params: { lang } }) {
  console.log("lang", lang);

  const menuLang = await getDictionary(lang)
  const getUser = async () => {
    "use server";
    try {
      const currentUser = await getCurrentUser();
      return currentUser;
    }catch(error){
      return { message: "获取失败: " + error.message, success: false };
    }
  }
  const currentUser = await getUser();
  return (
    <html lang="en" suppressHydrationWarning>
    <head>
      <title>半岛网球场地预订</title>
    </head>
      <body  className={cn(
          "min-h-screen bg-background font-sans antialiased",
          fontSans.variable
        )}>
        <TrackerProvider>
        <LayoutClient
        menuLang={menuLang}
        currentUser={currentUser||{}}
        wxConfig={wxJsConfig}
        >
          {children}
        </LayoutClient>
        </TrackerProvider>
        <Toaster />
        <SonnerToaster />
      </body>
    </html>
  );
}
